package grape.sequence.rest.generator.mvc;

import grape.common.rest.mvc.SuperController;
import grape.sequence.service.generator.api.ISequenceGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 序列生成 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-08-20
 */
@RestController
@RequestMapping("/sequence/generator/inner")
@ApiIgnore
public class GeneratorInnerController extends SuperController {

    @Autowired
    private ISequenceGenerator iSequenceGenerator;


    /**
     * 根据配置编码获取下一个序列
     * @param code
     * @return
     */
    @GetMapping("/code/{code}/next")
    @ResponseStatus(HttpStatus.OK)
    public String nextByCode(@PathVariable String code) {
        return iSequenceGenerator.nextSeqValueByConfigCode(code);
    }

    /**
     * 根据配置id获取下一个序列
     * @param id
     * @return
     */
    @GetMapping("/id/{id}/next")
    @ResponseStatus(HttpStatus.OK)
    public String nextById(@PathVariable String id) {
        return iSequenceGenerator.nextSeqValueByConfigId(id);
    }
}
